﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Drawing;
using System.Drawing.Imaging;

namespace WebSite.Core
{
    public class TeamHelper
    {
        public static string CombinTeamHead( string img1, string img2 )
        {
            string outfile = "/UploadImages/Team/" + Guid.NewGuid().ToString( "N" ) + ".jpg";
            CombinTeamHead( "/Images/teamphotobase.jpg", img1, img2, outfile );
            return outfile;
        }

        public static void CombinTeamHead( string imgbase, string img1, string img2, string outfile )
        {
            using (Bitmap under = new Bitmap( 660, 420 ))
            {
                using (Graphics g = Graphics.FromImage( under ))
                {
                    using (Image bbase = Bitmap.FromFile( HttpContext.Current.Server.MapPath( imgbase ) ),
                        b1 = Bitmap.FromFile( HttpContext.Current.Server.MapPath( img1 ) ),
                        b2 = Bitmap.FromFile( HttpContext.Current.Server.MapPath( img2 ) ))
                    {

                        g.DrawImage( bbase, 0, 0, bbase.Width, bbase.Height );
                        g.DrawImage( b1, 27, 79, 300, 300 );
                        g.DrawImage( b2, 334, 79, 300, 300 );
                    }

                    EncoderParameters ep = new EncoderParameters();
                    ep.Param[0] = new EncoderParameter( Encoder.Quality, (long)80 );

                    under.Save( HttpContext.Current.Server.MapPath( outfile ), ImageFormat.Jpeg );
                }
            }
        }

        public static string CombinOneTeamHead( string img1 )
        {
            string outfile = "/UploadImages/Team/" + Guid.NewGuid().ToString( "N" ) + ".jpg";
            CombinOneTeamHead( "/Images/teamphotobase.jpg", img1, outfile );
            return outfile;
        }

        public static void CombinOneTeamHead( string imgbase, string img1, string outfile )
        {
            using (Bitmap under = new Bitmap( 660, 420 ))
            {
                using (Graphics g = Graphics.FromImage( under ))
                {
                    using (Image bbase = Bitmap.FromFile( HttpContext.Current.Server.MapPath( imgbase ) ),
                        b1 = Bitmap.FromFile( HttpContext.Current.Server.MapPath( img1 ) ) )
                    {

                        g.DrawImage( bbase, 0, 0, bbase.Width, bbase.Height );
                        g.DrawImage( b1, 27, 79, 606, 300 );
                    }

                    EncoderParameters ep = new EncoderParameters();
                    ep.Param[0] = new EncoderParameter( Encoder.Quality, (long)80 );

                    under.Save( HttpContext.Current.Server.MapPath( outfile ), ImageFormat.Jpeg );
                }
            }
        }
    }
}